package com.wxm.common.file.start;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;

import java.time.LocalDateTime;

/**
 * <p>
 *      全局返回类
 * </p>
 *
 * @author: wxm
 * @Date: 2022/1/25
 */
public class R<T> {
    @Getter
    private String msg = "成功";
    @Getter
    private T data = null;
    @Getter
    private Integer code = 200;
    @Getter
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private final LocalDateTime timestamp = LocalDateTime.now();

    private R(T data){
        this.data = data;
    }
    private R(Integer code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public static <T> R<T> ok(T data){
        return new R<T>(data);
    }
    public static <T> R<T> error(String msg){
        return new R<T>(500,msg);
    }
}
